import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/version/management',
    name: '更新管理',
    iconClass: 'fa fa-address-book-o',
    component: () => import('@/views/MgtCenterView.vue'),
    children: [
    ]
  },
  {
    path: '/infrastructure',
    name: '基础设施',
    iconClass: 'fa fa-address-book-o',
    component: () => import('@/views/MgtCenterView.vue'),
    children: [
      {
        path: '/infrastructure/operlog',
        name: '操作日志',
        component: () => import('@/views/Log/OpsLog.vue')
      },
      {
        path: '/infrastructure/dictdata',
        name: '字典数据',
        component: () => import('@/views/DictData/DictData.vue')
      },
      {
        path: '/infrastructure/dicttype',
        name: '字典类型',
        component: () => import('@/views/DictType/DictType.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach(function (to, from, next) {
  success2Next(to, from, next)
})

// 用户校验成功，跳转到下一地址
function success2Next (to, from, next) {
  // 默认路径跳转到MyApplication页面
  console.log('to path:', to)
  if (to.path === '/') {
    // 默认地址
    next('/infrastructure/operlog')
  } else {
    // 其他路径
    next()
  }
}

export default router
